import os
import sys
import time

from selenium import webdriver
from selenium.webdriver.common.by import By
import pytest
from selenium.webdriver.support.wait import WebDriverWait  # 等待模块
from selenium.webdriver.support import expected_conditions as ec


class Register:
    def driver(self):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90/toregister.html")
        driver.maximize_window()
        return driver

    def register(self, username, password,repassword, driver):
        driver.implicitly_wait(5)
        driver.find_element(By.XPATH, '//*[@id="username"]').send_keys(username)
        driver.find_element(By.XPATH, '//*[@id="password"]').send_keys(password)
        driver.find_element(By.XPATH, '//*[@id="repassword"]').send_keys(repassword)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        time.sleep(1)
        return driver

    def GetSuccessResult(self, driver):
        return driver.title

    def assertResult(self, result, expect, driver):
        if result == expect:
            print("通过！")
        else:
            print("不通过！")
            os.makedirs("py/WebAuto/Test/error",exist_ok=True)
            driver.save_screenshot("./WebAuto/Test/error/register.jpg")
        assert result==expect